package com.bgt.utils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import org.apache.commons.beanutils.BasicDynaBean;
import org.apache.commons.beanutils.BasicDynaClass;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;

public class BeanWrapper {

	List<DynaProperty> dynaBeanProperties;

	public BeanWrapper() {
		dynaBeanProperties = new ArrayList<DynaProperty>();
	}

	public void addStringProperty(String name) {
		dynaBeanProperties.add(new DynaProperty(name, String.class));
	}

	public void addIntegerProperty(String name) {
		dynaBeanProperties.add(new DynaProperty(name, Integer.class));
	}

	public void addDateProperty(String name) {
		dynaBeanProperties.add(new DynaProperty(name, Date.class));
	}

	public void addFloatProperty(String name) {
		dynaBeanProperties.add(new DynaProperty(name, Float.class));
	}

	public void addBooleanProperty(String name) {
		dynaBeanProperties.add(new DynaProperty(name, Boolean.class));
	}

	public void addListProperty(String name) {
		dynaBeanProperties.add(new DynaProperty(name, List.class));
	}

	public void addSetProperty(String name) {
		dynaBeanProperties.add(new DynaProperty(name, Set.class));
	}

	public void addLongProperty(String name) {
		dynaBeanProperties.add(new DynaProperty(name, Long.class));
	}

	public Bean getBean(String beanName) throws Exception {
		BasicDynaClass dynaClass = new BasicDynaClass(beanName,
				BasicDynaBean.class, dynaBeanProperties
						.toArray(new DynaProperty[dynaBeanProperties.size()]));
		DynaBean dynaBean = dynaClass.newInstance();
		return new Bean(dynaBean, dynaBeanProperties);
	}

	public List<DynaProperty> getProperties() {
		return this.dynaBeanProperties;
	}

}
